/*
 * avr035.h
 *
 * Created: 17.10.2013
 *  Author: qw3r
 */


#ifndef AVR035_H_
#define AVR035_H_

/*
 * From AVR035: Efficient C Coding for AVR
 * http://www.atmel.com/Images/doc1497.pdf
 */

#define SETBIT(ADDRESS,BIT)		( ADDRESS |= (1<<BIT) )
#define CLEARBIT(ADDRESS,BIT)	( ADDRESS &= ~(1<<BIT) )
#define FLIPBIT(ADDRESS,BIT)	( ADDRESS ^= (1<<BIT) )
#define CHECKBIT(ADDRESS,BIT)	( ADDRESS & (1<<BIT) )

#define SETBITMASK(x,y)			( x |= (y) )
#define CLEARBITMASK(x,y)		( x &= (~y) )
#define FLIPBITMASK(x,y)		( x ^= (y) )
#define CHECKBITMASK(x,y)		( x & (y) )

/*
 * Extended commands
 * usage:
 * #define Status_LED PORTA, 3
 *
 * C_SETBIT(Status_LED);
 * C_CLEARBIT(Status_LED);
 */

#define VARFROMCOMB(x, y)		x
#define BITFROMCOMB(x, y)		y

#define C_SETBIT(comb)			SETBIT   ( VARFROMCOMB(comb), BITFROMCOMB(comb) )
#define C_CLEARBIT(comb)		CLEARBIT ( VARFROMCOMB(comb), BITFROMCOMB(comb) )
#define C_FLIPBIT(comb)			FLIPBIT  ( VARFROMCOMB(comb), BITFROMCOMB(comb) )
#define C_CHECKBIT(comb)		CHECKBIT ( VARFROMCOMB(comb), BITFROMCOMB(comb) )

#endif /* AVR035_H_ */